package com.cyzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyzy.mapper.UserMapper;
import com.cyzy.pojo.Passenger;
import com.cyzy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, Passenger> implements UserService{

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<Passenger> selectUserList() {
        QueryWrapper<Passenger> wrapper = new QueryWrapper<>();
        wrapper.ne("user_status",2);
        return this.list(wrapper);
    }

    @Override
    public List<Passenger> searchUserList(String name, String phone, String userAcc, String gender, String idCard, Integer userStatus) {
        return userMapper.selectUserList(name,phone,userAcc,gender,idCard,userStatus);
    }

    @Override
    public int updateManage(Integer userId, String name, String phone, String userAcc, String gender, String idCard, double balance, Integer userStatus, String avatar) {
        UpdateWrapper<Passenger> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("user_id", userId)  // 更新条件：user_id = userId
                .set("name", name)
                .set("phone", phone)
                .set("user_acc", userAcc)
                .set("gender", gender)
                .set("id_card", idCard)
                .set("balance", balance)
                .set("avatar", avatar)
                .set("user_status", userStatus);

        return userMapper.update(null, updateWrapper);
    }

    @Override
    public int deleteState(Integer userId, Integer userStatus) {
        UpdateWrapper<Passenger> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("user_id", userId)  // 更新条件：user_id = userId
                .set("user_status", 2);

        return userMapper.update(null, updateWrapper);
    }

    @Override
    public int deleteStateByIds(List<String> ids, String state) {
        UpdateWrapper<Passenger> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("user_id", ids)
                .set("user_status", 2);  // 假设 user_status 是你的状态字段名

        return userMapper.update(null, updateWrapper);
    }

}
